import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import user from './modules/user.js'
import cart from './modules/goodsCar.js'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		pageFlag: 'shop', // 导航页
		headerTop: '', // 导航栏高度
		menuButtonPoint: '',
		refresh: ''
	},
	mutations: {
		CHANGE_TAB(state, currentPage) {
			const userInfo = uni.getStorageSync('userInfo')
			if (currentPage == 'order' && !userInfo) {
				return uni.navigateTo({
					url: '/loginAndInfoPage/login/login'
				})
			}
			state.pageFlag = currentPage
		},
		SET_HEADER_TOP(state, headerTop) {
			state.headerTop = headerTop
		},
		GET_MENU_BUTTON(state) {
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			state.menuButtonPoint = menuButtonInfo.bottom * 2
		}
	},
	actions: {
		changeTab({
			commit
		}, curentPage) {
			return commit('CHANGE_TAB', curentPage)
		},
		setHeaderTop({
			commit
		}, headerTop) {
			return commit('SET_HEADER_TOP', headerTop)
		},
	},
	getters,
	modules: {
		user,
		cart
	}
})

export default store